<?php

/**
 * Description of WebUser
 *
 * @author jbcrouigneau
 */
class WebUser extends CWebUser
{
    // Set login URL
    public $loginUrl = array('account/login');

    // Store model to not repeat query.
    private $_model;

    // This is a function that checks the field 'is_admin'
    // in the User model to be equal to 1, that means it's admin
    // access it by Yii::app()->user->isAdmin()
    function isAdmin()
    {
        $user = $this->loadUser(Yii::app()->user->id);
        if ($user===NULL)
            return 0;
        else
            return $user->is_admin;
    }

    // Load user model.
    protected function loadUser($id=null)
    {
        if($this->_model===null)
        {
            if($id!==null)
                $this->_model=User::model()->findByAttributes(array('login'=>$id));
        }
        return $this->_model;
    }

}

?>
